package com.marlon.auto.dao;

import com.marlon.auto.entity.po.AreaInfoPO;
import com.marlon.auto.entity.vo.AreaInfoVO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author marlon
 * @since 2022-04-19
 */
public interface AreaInfoDao extends JpaRepositoryImplementation<AreaInfoPO, String> {

    @Query("select s from AreaInfoPO s where 1=1 " +
        " and (s.areaType = :#{#vo.areaType} or :#{#vo.areaType} is null or :#{#vo.areaType} = '') "+
        " and (lower(s.areaDesc) like %:#{#vo.keyword}% or lower(s.areaName) like %:#{#vo.keyword}% or (:#{#vo.keyword} =''))")
    Page<AreaInfoPO> findAllByVOAndKeyword(@Param("vo") AreaInfoVO query, Pageable page);

    @Query("select s from AreaInfoPO s where s.availState = '1' ")
    List<AreaInfoPO> findAllAvailable();
}